
package com.rabincorp.facepoll.application;

import com.rabincorp.facepoll.domain.services.poll.PollService;
import java.util.Date;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 *
 * @author isakrabin
 */
@Controller
@RequestMapping("/services")
public class PollAppServiceImpl implements PollAppService{
    
    private final static Log LOGGER = LogFactory.getLog(PollAppServiceImpl.class);

    @Autowired
    private PollService pollService;
    
    @RequestMapping(value = "/{id}", method= RequestMethod.POST)
    @Transactional(propagation= Propagation.REQUIRED, rollbackFor=Exception.class)
    @Override
    public void create(String title, String question, String active, String type, List<String> options, Date startDate, Date endDate) {
        
        LOGGER.info("Processing form - create new poll");
        
//        boolean hasError = false;
//        
//        if (StringUtils.isNullOrEmpty(title)) {
//            hasError = true;
//        }
//        
//        if (StringUtils.isNullOrEmpty(question)) {
//            hasError = true;
//        }
//        
//        if (options.isEmpty()) {
//            hasError = true;
//        }else if (options.size() <= FacepollConstant.MINIMUM_OPTIONS) {
//            hasError = true;
//        }
//        
//        if (startDate != null) {                       
//            //compare with today date
//        }
//        
//        if (endDate != null) {
//            
//            //compare with start date
//            if (startDate != null && startDate.before(endDate)) {
//                hasError = true;
//            }
//            
//        }
//        
//        if (!hasError) {
//            FacepollConstant.PollType pollType = FacepollConstant.PollType.valueOf(type); 
//            Boolean pollActive = Boolean.valueOf(active);
//            pollService.create(title, question, options, pollActive, pollType, startDate, endDate);
//        }

        
    }
    
}
